//
//  FriendImpressionTableViewCell.m
//  u76ho
//
//  Created by m-air-01 on 16/1/8.
//  Copyright © 2016年 LV. All rights reserved.
//

#import "FriendImpressionTableViewCell.h"
@interface FriendImpressionTableViewCell ()
{
    int totalW;
}
@end
@implementation FriendImpressionTableViewCell

- (void)awakeFromNib {
    // Initialization code
    UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(SIZETO5W(15), SIZETO6H(21), 150, 20)];
    lab.text = @"大家对我的印象是:";
    lab.tag = 1;
    lab.textColor = UIColorFromRGB(0x94999f);
    [self addSubview:lab];
    
//    UILabel * firstLab = [[UILabel alloc]initWithFrame:CGRectMake(SIZETO6W(15), lab.bottom+SIZETO6H(19), 100, 30)];
//    firstLab.textColor = UIColorFromRGB(0x6ec844);
//    firstLab.text = @"有为青年";
//    firstLab.layer.masksToBounds = YES;
//    firstLab.textAlignment = NSTextAlignmentCenter;
//    firstLab.layer.borderColor = [UIColorFromRGB(0x6ec844) CGColor];
//    firstLab.layer.borderWidth = 1.0f;
//    firstLab.layer.cornerRadius = 15;
//    [self addSubview:firstLab];
}

-(void)setDataArr:(NSArray *)dataArr
{
    int j = 0;
    totalW = 0;
    UILabel * _friendImpressionLab = (UILabel *)[self viewWithTag:1];
    _dataArr = dataArr;
    NSMutableArray * mArr = [[NSMutableArray alloc]init];
    for (int i = 0; i<dataArr.count; i++) {
        FirendImpretionModel * model = dataArr[i];
        [mArr addObject:model.tags];
    }
    CGFloat h = 30;
    CGFloat myWidth = SCREEN_WIDTH - SIZETO6W(30);
    for (int i = 0; i<mArr.count; i++) {
        NSString * str = [mArr objectAtIndex:i];
        CGFloat tempW = [str widthOfSize:18] + SIZETO6W(10);
        totalW += tempW+SIZETO6W(10);
        if (totalW<=myWidth) {
            UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake(SIZETO6W(15)+totalW-tempW-SIZETO6W(10),_friendImpressionLab.bottom +5+j*(h + SIZETO6H(10)), tempW, h);
            [btn setTitle:mArr[i] forState:UIControlStateNormal];
            [btn setTitleColor:UIColorFromRGB(0x6ec844) forState:UIControlStateNormal];
            btn.layer.masksToBounds = YES;
            btn.layer.borderColor = [UIColorFromRGB(0x6ec844) CGColor];
            btn.layer.borderWidth = 1.0f;
            btn.layer.cornerRadius = 15;
            btn.titleLabel.font = [UIFont systemFontOfSize:15];
            [self addSubview:btn];
        }
        else
        {
            totalW = tempW+SIZETO6W(10);
            j = j+1;
            UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake(SIZETO6W(15), _friendImpressionLab.bottom +5+j*(h + SIZETO6H(10)), tempW, h);
            [btn setTitle:mArr[i] forState:UIControlStateNormal];
            [btn setTitleColor:UIColorFromRGB(0x6ec844) forState:UIControlStateNormal];
            btn.layer.masksToBounds = YES;
            btn.layer.borderColor = [UIColorFromRGB(0x6ec844) CGColor];
            btn.layer.borderWidth = 1.0f;
            btn.layer.cornerRadius = 15;
            btn.titleLabel.font = [UIFont systemFontOfSize:15];
            [self addSubview:btn];
            
        }
    }
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
